package com.example.layui_project.comm.service.Impl;

import com.example.layui_project.comm.dao.BaseDao;
import com.example.layui_project.comm.service.BaseService;
import com.example.layui_project.dto.TableParams;
import com.example.layui_project.dto.TableResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl <T>{
    @Autowired
    protected BaseDao<T> baseDao;

    public TableResult<T> find(TableParams tableParams) {
        TableResult<T> tableResult = new TableResult<T>();
        tableResult.setData(findTbaleData(tableParams));
        tableResult.setCount(findTableTotal(tableParams));
        return tableResult;
    }

    private Integer findTableTotal(TableParams tableParams) {
        return baseDao.getTableCount(tableParams);
    }

    private List<T> findTbaleData(TableParams tableParams) {
        return baseDao.getTableRows(tableParams);
    }
}
